package com.ricky.game;

import java.util.HashMap;
import java.util.Map;

import com.ricky.core.net.abs.Request;
import com.ricky.core.net.msg.AMF3Context;
import com.ricky.core.net.msg.Context;


/**
 * 消息辅助类
 * @author rik
 *
 */
public class MsgHelper {

	/**
	 * 	发送tips消息
	 * @param req
	 * @param tips
	 */
	@SuppressWarnings("unchecked")
	public static void sendTips(Request req,String tips)
	{
		AMF3Context amf=new AMF3Context();
		@SuppressWarnings("rawtypes")
		Map tip=new HashMap<String,String>();
		tip.put("cmd", "showTips");
		tip.put("arg", tips);
		amf.setContent(tip);
		if(req!=null && req.isConnected())
			req.sendMessage(amf);
	}
	
	/**
	 * 发送tips消息
	 * @param heroName
	 * @param tips
	 */
	public static void sendTips(String heroName,String tips)
	{
		Request req=GameWorld.heroRequest.get(heroName);
		sendTips(req,tips);
	}
	

	/**
	 * 发送消息到指定客户端
	 * @param heroName
	 * @param data
	 */
	public static void sendMsg(String heroName,@SuppressWarnings("rawtypes") Context<Map> data)
	{
		Request req=GameWorld.heroRequest.get(heroName);
		sendMsg(req,data);
	}
	
	/**
	 * 发送消息到指定客户端
	 * @param req
	 * @param data
	 */
	@SuppressWarnings("rawtypes")
	public static void sendMsg(Request req,Context<Map> data)
	{
		if(req!=null && req.isConnected())
			req.sendMessage(data);
	}
	
	/**
	 * 发送消息到指定客户端
	 * @param heroName
	 * @param data
	 */
	public static void sendMsg(String heroName,@SuppressWarnings("rawtypes") Map data)
	{
		AMF3Context amf=new AMF3Context();
		amf.setContent(data);
		sendMsg(heroName,amf);
	}
	
	/**
	 * 发送消息到客户端
	 * @param heroName
	 * @param data
	 */
	public static void sendMsg(Request req,@SuppressWarnings("rawtypes") Map data)
	{
		AMF3Context amf=new AMF3Context();
		amf.setContent(data);
		sendMsg(req,amf);
	}
}
